package com.lysj.admin.auth.management.service;


import com.lysj.admin.auth.management.domain.Role;
import com.lysj.admin.auth.management.repository.RoleRepository;
import com.lysj.admin.utils.constant.CommonConstant;
import com.lysj.admin.utils.spring.foundation.base.BaseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.transaction.Transactional;
import java.util.List;

/**
 * @author zk
 * @description 角色表服务层
 * @create 2018-07-25 15:10:47
 **/
@Slf4j
@Service
@Transactional
public class RoleService implements BaseService<Role> {

    @Resource
    private RoleRepository roleRepository;

    @Override
    public RoleRepository getRepository() {
        return roleRepository;
    }

    /**
     * @author zk
     * @date 2018-08-13 20:26
     * @Description 判断该角色是否存在
     */
    public boolean countRoleId(String id) {
        boolean flag = roleRepository.countByIdAndDelFlag(id, CommonConstant.NORMAL_FLAG) > 0 ? true : false;
        return flag;
    }

    public List<Role> findByDefaultRole(boolean isDefault) {
        return roleRepository.findByDefaultRoleAndDelFlag(isDefault, CommonConstant.NORMAL_FLAG);
    }
}